from drf_yasg.utils import swagger_serializer_method
from rest_framework import serializers

from lab.credit.models import CreditScoreDetail
from lab.user.models import ExtendedUser


class CreditScoreListSerializer(serializers.ModelSerializer):
    class Meta:
        model = CreditScoreDetail
        fields = ['id', 'order_number', 'apply_type', 'created_time', 'status']


class CreditScoreDetailSerializer(serializers.ModelSerializer):
    user_name = serializers.SerializerMethodField()

    @swagger_serializer_method(serializer_or_field=serializers.CharField)
    def get_user_name(self, obj):
        return ExtendedUser.objects.filter(id=obj.user_id).first().user.username

    class Meta:
        model = CreditScoreDetail
        fields = ['id', 'order_number', 'apply_type', 'created_time', 'status', 'picture_url', 'reject_reason',
                  'user_name']
